<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
</head>
<body>
<div class="layui-side layui-bg-black" id="admin-side">
    <div class="layui-side-scroll" id="admin-navbar-side" lay-filter="side"></div>
</div>
</body>

<script type="application/javascript">

    /** index.js By Beginner Emain:zheng_jinfan@126.com HomePage:http://www.zhengjinfan.cn */
    layui.config({
        base: '/static/js/mod/',
        version: new Date().getTime()
    }).use(['element', 'layer', 'navbar', 'tab', 'jquery'], function () {
        let element = layui.element,
            navbar = layui.navbar();

        $ = layui.jquery;
        layer = layui.layer;

        tab = layui.tab({
            elem: '.admin-nav-card', //设置选项卡容器
            //maxSetting: {
            //	max: 5,
            //	tipMsg: '只能开5个哇，不能再开了。真的。'
            //},
            contextMenu: true,
            onSwitch: function (data) {
                // console.log(data.id); //当前Tab的Id
                // console.log(data.index); //得到当前Tab的所在下标
                // console.log(data.elem); //得到当前的Tab大容器
                // console.log(tab.getCurrentTabId())
            },
            closeBefore: function (obj) { //tab 关闭之前触发的事件
                // console.log(obj);
                if (obj.title === 'BTable') {
                    confirm('确定要关闭' + obj.title + '吗?', function (index) {
                        //因为confirm是非阻塞的，所以这里关闭当前tab需要调用一下deleteTab方法
                        tab.deleteTab(obj.tabId);
                        layer.close(index);
                    });
                    //返回true会直接关闭当前tab
                    return false;
                } else if (obj.title === '表单') {
                    confirm('未保存的数据可能会丢失哦，确定要关闭吗?', function (index) {
                        tab.deleteTab(obj.tabId);
                        layer.close(index);
                    });
                    return false;
                }
                return true;
            }
        });

        /* iframe自适应 */
        $(window).on('resize', function () {
            var $content = $('.admin-nav-card .layui-tab-content');
            $content.height($(this).height() - 147);
            $content.find('iframe').each(function () {
                $(this).height($content.height());
            });
        }).resize();

        /* 加载菜单 */
        $.getScript('/static/datas/nav.js', function () {
            //设置navbar
            navbar.set({
                spreadOne: true,
                elem: '#admin-navbar-side',
                cached: true,
                data: navs
            });
            //渲染navbar
            navbar.render();

            startVue();

            //监听点击事件
            navbar.on('click(side)', function (data) {
                console.log('click(side) -> ' + JSON.stringify(data.field));
                if (data && data.field && data.field.href) {
                    data.field.href = getTextReqPath(data.field.href);
                    tab.tabAdd(data.field);
                } else {
                    alert('路径错误');
                }
            });
        });

        /* 清除缓存 */
        $('#clearCached').on('click', function () {
            console.log('clearCached');
            navbar.cleanCached();
            alert("清除完成!", function () {
                location.reload(); //刷新
            });
        });

        /* 缩小菜单 */
        $('.admin-side-toggle').on('click', function () {
            var sideWidth = $('#admin-side').width();
            if (sideWidth === 200) {
                $('#admin-body').animate({
                    left: '0'
                }); //admin-footer
                $('#admin-footer').animate({
                    left: '0'
                });
                $('#admin-side').animate({
                    width: '0'
                });
            } else {
                $('#admin-body').animate({
                    left: '200px'
                });
                $('#admin-footer').animate({
                    left: '200px'
                });
                $('#admin-side').animate({
                    width: '200px'
                });
            }
        });

        /* 全屏 */
        $('.admin-side-full').on('click', function () {
            var docElm = document.documentElement;
            //W3C
            if (docElm.requestFullscreen) {
                docElm.requestFullscreen();
            }
            //FireFox
            else if (docElm.mozRequestFullScreen) {
                docElm.mozRequestFullScreen();
            }
            //Chrome等
            else if (docElm.webkitRequestFullScreen) {
                docElm.webkitRequestFullScreen();
            }
            //IE11
            else if (elem.msRequestFullscreen) {
                elem.msRequestFullscreen();
            }
            msg('按Esc即可退出全屏');
        });

        $('#setting').on('click', function (e) {
            let url = e.currentTarget.dataset.url;
            if (url) {
                tab.tabAdd({
                    href: url,
                    icon: 'fa-gear',
                    title: '配置中心'
                });
            } else {
                alert('加载失败!')
            }
        });

        $('.laohu-open-url').on('click', function (e) {
            let url = e.currentTarget.dataset.url;
            if (url) {
                openUrl(url);
            } else {
                alert('加载失败!')
            }
        });

        /* 手机设备的简单适配 */
        var treeMobile = $('.site-tree-mobile'),
            shadeMobile = $('.site-mobile-shade');
        treeMobile.on('click', function () {
            $('body').addClass('site-mobile');
        });
        shadeMobile.on('click', function () {
            $('body').removeClass('site-mobile');
        });
    });

</script>
</html>
